package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.Label;
import com.juyu.miliao.api.domain.UserLikeLabel;
import com.juyu.miliao.api.domain.UserMeLabel;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class LabelDao {
	@Autowired
	private SqlSession sqlSession;

	public List<Label> getLabelList(Integer sex) {
		return sqlSession.selectList("getLabelList", sex);
	}

	@Operate("strategy('byUserId', #userId)")
	public List<Label> getLabelCountByUserId(Long userId){
		return sqlSession.selectList("getLabelCountByUserId", userId);
	}

	@Operate("strategy('byUserId', #userId)")
	public int insertUserLabel(int userId, int label){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("label", label);
		return sqlSession.insert("insertUserLabel", params);
	}

	/**
	 * 查询主播是否是第一次选择自我评价标签
	 * @param userId
	 * @return
	 */
	@Operate("strategy('byUserId', #userId)")
	public List<UserMeLabel> getUserIdForMeLable(long userId) {
		return sqlSession.selectList("getUserIdForMeLabel",userId);
	}

	/**
	 * 删除
	 * @param userId
	 */
	@Operate("strategy('byUserId', #userId)")
	public void delUserIdForMeLabel(long userId) {
		sqlSession.delete("delUserIdForMeLabel",userId);
	}

	/**
	 * 插入自我评价标签
	 * @param userId
	 * @param id
	 */
	@Operate("strategy('byUserId', #userId)")
	public void insertLabelForUserMeLabel(long userId, long id) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("label", id);
		sqlSession.insert("saveLabelForUserMeLabel",params);
	}

    /**
     * 获取带指定标签的主播
     * @param userId
     * @param labelId
     * @return
     */
    @Operate("strategy('byUserId', #userId)")
    public UserMeLabel getUserIdForUserMeLabel(Long userId, String labelId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("label", Long.valueOf(labelId));
       return sqlSession.selectOne("getUserIdForUserMeLabel",params);
    }
}